/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jl.tools.stkeditor.manager;

import com.jl.tools.stkeditor.generate.ASCIICode;
import com.jl.tools.stkeditor.generate.Add80;
import com.jl.tools.stkeditor.generate.AddCodeHead;
import com.jl.tools.stkeditor.generate.AddCodeSplite;
import com.jl.tools.stkeditor.generate.AddItemTag;
import com.jl.tools.stkeditor.generate.AddNormalTag;
import com.jl.tools.stkeditor.generate.AddNote;
import com.jl.tools.stkeditor.generate.AddSpace;
import com.jl.tools.stkeditor.generate.Bit7Code;
import com.jl.tools.stkeditor.generate.Code;
import com.jl.tools.stkeditor.generate.OriginalCode;
import com.jl.tools.stkeditor.generate.UnicodeCode;

/**
 * 
 * @author LuHongjun
 */
public class ParseCommand {

	public static Code getCodeObject(LineInfo info) {

		Code code = null;
		if (info.getCodeScheame().equals(CodingType.ASCII)) {
			code = new ASCIICode(info.getText());
		} else if (info.getCodeScheame().equals(CodingType.BIT7)) {
			code = new Bit7Code(info.getText());
		} else if (info.getCodeScheame().equals(CodingType.ORIGINAL)) {
			code = new OriginalCode(info.getText());
		} else {
			code = new UnicodeCode(info.getText());
		}
		if (info.isWith80()) {
			code = new Add80(code);
		}
		if (info.getTag().equalsIgnoreCase("item")) {
			code = new AddItemTag(code, info.getIndex());
		} else {
			if (!info.getTag().trim().equals("")) {
				code = new AddNormalTag(code, info.getTag());
			}
		}
		code = new AddCodeSplite(code, ",");
		code = new AddCodeHead(code, "(byte)0x");
		code = new AddSpace(code, 4);
		code = new AddNote(code, info.toString());
		return code;
	}
}
